﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GiaoTrinhEPU.Repositories;

namespace GiaoTrinhEPU.Helpers.ManagerMenuBuilder
{
    public static class ManagerLinkListHelper
    {
        public static int GetTopLevelParentId(IEnumerable<Menu> managerLinks)
        {
            return managerLinks.OrderBy(i => i.ParentId).Select(i => i.ParentId).FirstOrDefault();
        }

        public static bool ManagerLinkHasChildren(IEnumerable<Menu> managerLinks, int id)
        {
            return managerLinks.Any(i => i.ParentId == id);
        }

        public static IEnumerable<Menu> GetChildManagerLinks(IEnumerable<Menu> managerLinks,int parentIdForChildren)
        {
            return managerLinks.Where(i => i.ParentId == parentIdForChildren)
                .OrderBy(i => i.Ordering).ThenBy(i => i.Name);
        }
    }
}
